{include 'admin/layout/header_list'}
<link rel="stylesheet" href="__ADMIN_STATIC__/css/plugin.css?random={extendSetting('random')}">
<link rel="stylesheet" href="__ADMIN_STATIC__/css/pop_window.css?random={extendSetting('random')}">
<link rel="stylesheet" href="__ADMIN_STATIC__/css/iconfont.css?random={extendSetting('random')}">
<div class="ltcms_container">
    <div class="container_title">
        <form action="{LTCMS_ROUTE_PREFIX}/appStore" method="get" class="ltcms_search">
            <input type="hidden" name="categoryId" value="{if isset($request['categoryId'])}{$request['categoryId']}{/if}" />
            <input type="hidden" name="installed" value="{if isset($request['installed'])}{$request['installed']}{/if}" />
            <input name="name" type="text" placeholder="请输入软件名称" {if isset($request['name'])} value="{$request['name']}" {/if}>
            <button type="submit" class="btn3">搜索</button>
            <!--<div class="select_box list-change" title="切换列表显示方式">-->
                <!--<i class="iconfont icon-liebiao"></i>-->
            <!--</div>-->
        </form>
        <ul class="title_tab1">
            <a href="{LTCMS_ROUTE_PREFIX}/appStore" ><li style="width:auto;" class="{if !$request['categoryId'] && !$request['installed']}on{/if}">全部</li></a>
            <a href="{LTCMS_ROUTE_PREFIX}/appStore?installed=1" ><li style="width:auto;" class="{if isset($request['installed']) && $request['installed']=='1'}on{/if}">已安装</li></a>
            {foreach $category $val}
            <a href="{LTCMS_ROUTE_PREFIX}/appStore?categoryId={$val['id']}" ><li style="width:auto;" class="{if isset($request['categoryId']) && $request['categoryId']==$val['id']}on{/if}"  >{$val['name']}</li></a>
            {/foreach}
        </ul>
    </div>
    <section class="ltcms_content">
        <div class="ltcms_list">
            <table class="list_table">
                <colgroup>
                    <col width="190px">
                    <col width="60px">
                    <col>
                    <col width="100px">
                    <col width="180px">
                    <col width="200px">
                </colgroup>
                <tr>
                    <td class="th">软件名称</td>
                    <td class="th">状态</td>
                    <td class="th">描述</td>
                    <td class="th">价格/天</td>
                    <td class="th">到期时间</td>
                    <td class="th" style="text-align: right;">操作</td>
                </tr>
                {if $listData}
                {php $nowTime=time();}
                {foreach $listData["data"] $key $val}
                <tr>
                    <td>
                        <a href="https://www.ltcms.com/market/{$val['id']}.html" target="_blank" >
                            {$val["name"]}
                        </a>
                    </td>
                    <td>
                        {if isset($val['pluginData']['setting']["status"]) && $val['pluginData']['setting']["status"]=="1"}
                        <div class="switch close1">
                            <span class="left"></span>
                            <span class="right"></span>
                            <span class="switch_box close2"></span>
                        </div>
                        {else}
                        <div class="switch open1">
                            <span class="left"></span>
                            <span class="right"></span>
                            <span class="switch_box open2"></span>
                        </div>
                        {/if}
                    </td>
                    <td>{$val['description']}  {if isset($val['pluginData']["nickname"])}作者：{$val['pluginData']["nickname"]}{/if}</td>
                    <td>{if isset($val['sellPrice'])}￥{$val['sellPrice']}{else}---{/if}</td>
                    <td>
                        {if isset($val['pluginData']["isPermanent"])}
                            {if $val['pluginData']["isPermanent"]=="1"}
                                永久
                            {else}
                                {if $val['pluginData']["expireMax"] > $nowTime}
                                {date('Y-m-d H:i:s',$val['pluginData']["expireMax"])}
                                {/if}
                            {/if}
                        {else}
                            ---
                        {/if}
                    </td>
                    <td style="text-align: right;" >
                        {if isset($val['pluginData']["isPermanent"]) && $val['pluginData']["isPermanent"]=="1" || $val['pluginData']["expireMax"] > $nowTime}
                            <div class="btn4">
                                {if isset($val['pluginData'])}
                                    {if $val['pluginData']["install"]=="0"}
                                        <a  href="javascript:void(0);" onclick="pop4('{LTCMS_ROUTE_PREFIX}/plugin/info?goodId={$val['id']}&pluginId={$val['pluginData']['id']}', '600px', '500px');" title="安装">
                                            <i class="btn4-img iconfont icon-ruanjianshengji"></i>
                                        </a>
                                    {else}
                                        {if array_path($val['pluginData'],'setting.setUpView.enable',0)==1}
                                            <a class="" href="javascript:void(0);" title="设置" onclick="openPluginsSetting('{$val['pluginData']['pluginDir']}',{array_path($val['pluginData'],'setting.setUpView.width',50)},{array_path($val['pluginData'],'setting.setUpView.height',50)})">
                                                <i class="btn4-img iconfont icon-setting"></i>
                                            </a>
                                        {/if}
                                        <a href="javascript:void(0);" title="卸载" onclick="uninstall('{$val['pluginData']['pluginDir']}','{$val['pluginData']['name']}')">
                                            <i class="btn4-img iconfont icon-delete"></i>
                                        </a>
                                        {if $val['id'] >0 && $val['pluginData']['id'] > 0}
                                            <a href="javascript:void(0);" onclick="pop4('{LTCMS_ROUTE_PREFIX}/plugin/info?goodId={$val['id']}&pluginId={$val['pluginData']['id']}', '600px', '500px');" title="升级">
                                                <i class="btn4-img iconfont icon-ruanjianshengji"></i>
                                            </a>
                                        {/if}
                                    {/if}
                                {/if}
                            </div>
                        {else}
                            <div class="btn4">
                                {if $val['pluginData']["install"]=="1"}
                                    {if array_path($val['pluginData'],'setting.setUpView.enable',0)==1}
                                    <a class="" href="javascript:void(0);" title="设置" onclick="openPluginsSetting('{$val['pluginData']['pluginDir']}',{array_path($val['pluginData'],'setting.setUpView.width',50)},{array_path($val['pluginData'],'setting.setUpView.height',50)})">
                                        <i class="btn4-img iconfont icon-setting"></i>
                                    </a>
                                    {/if}
                                    <a href="javascript:void(0);" title="卸载" onclick="uninstall('{$val['pluginData']['pluginDir']}','{$val['pluginData']['name']}')">
                                        <i class="btn4-img iconfont icon-delete"></i>
                                    </a>
                                    {if $val['id'] >0 && $val['pluginData']['id'] > 0}
                                    <a href="javascript:void(0);" onclick="pop4('{LTCMS_ROUTE_PREFIX}/plugin/info?goodId={$val['id']}&pluginId={$val['pluginData']['id']}', '600px', '500px');" title="升级">
                                        <i class="btn4-img iconfont icon-ruanjianshengji"></i>
                                    </a>
                                    {/if}
                                {else}
                                    <a href="https://www.ltcms.com/market/{$val['id']}.html" target="_blank" title="立即购买">
                                        <i class="btn4-img iconfont icon-goumai"></i>
                                    </a>
                                {/if}
                            </div>
                        {/if}
                    </td>
                </tr>
                {/foreach}
                {/if}
            </table>
        </div>
    </section>
    <div class="list-bottom">
        <div class="bottom-left">
            <a href="{LTCMS_ROUTE_PREFIX}/usedByCardName">
                <button class="btn2 trash">激活插件</button>
            </a>
            {if env()->get("APP_debug", "")==1}
            <!--开发者模式安装未上架测插件-->
            <button class="btn2 trash" onclick="pluginInstall()" >安装本地插件</button>
            {/if}
        </div>
        <div class="pages">
            {if $listData}
            {php echo app("P_page")->getPageBarV2($listData);}
            {/if}
        </div>
    </div>
</div>
<script src="__ADMIN_STATIC__/js/pop_window.js?random={extendSetting('random')}"></script>
<script src="__ADMIN_STATIC__/js/list.js?random={extendSetting('random')}"></script>
<script>
    function openPluginsSetting(pluginDir, x = 660, y = 660) {
        let url = "{LTCMS_ROUTE_PREFIX}/setUpView?pluginDir=" + pluginDir
        pop("安装", url, x + 'px', y + 'px'); //这个可以带关闭按钮
    }

    //卸载插件
    function uninstall(pluginDir, name) {
        layer.confirm('您确定要卸载[' + name + ']吗？', {
            title: "操作提示",
            icon: 0,
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            //按钮【按钮一】的回调
            let msgIndex = layer.msg('正在处理', {
                icon: 16,
                shade: 0.05,
                time: 60000
            });
            $.post("{LTCMS_ROUTE_PREFIX}/uninstall", {_method: "delete",pluginDir: pluginDir,},function (data, status) {
                layer.close(msgIndex);
                layer.msg(data.codeMsg, {
                    icon: data.code === 0 ? 1 : 2,
                    time: 1000
                });
                if (data.code === 0) {
                    location.reload(); //卸载完成刷新页面
                }
            });
        });
    }

    function pluginInstall() {
        //输入插件路径
        let path = prompt("请输入插件路径", "");
        if(path){
            let url='/api/execScript/pluginInstall?pluginDir='+path;
            //打开新窗口访问改地址
            window.open(url);
        }
    }
</script>
{include 'admin/layout/footer'}